<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {assign} smarty function plugin
 *
 * Type:     smarty function<br>
 * Name:     assign<br>
 * Purpose:  assign a value to a template variable
 * @link http://smarty.php.net/manual/en/language.custom.functions.php#LANGUAGE.FUNCTION.ASSIGN {assign}
 *       (Smarty online manual)
 * @author Monte Ohrt <monte at ohrt dot com> (initial author)
 * @auther messju mohr <messju at lammfellpuschen dot de> (conversion to smarty function)
 * @param string containing var-attribute and value-attribute
 * @param Smarty_smarty
 */
function smarty_core_smarty_gv($params, &$smarty)
{
    foreach($params as $key=>$val){
		$params[$key] = trim($params[$key],"'");
		$params[$key] = trim($params[$key],'"');
	}

    if (!isset($params['var'])) {
        $smarty->_syntax_error("assign: missing 'var' parameter", E_USER_WARNING);
        return;
    }
	foreach ($params as $key=>$val){
		$params[$key] = trim($val,"'");
	}

	$columns = $smarty->_tpl_vars['columns'];
	
	if (isset($params['cid']))
	{
		$column = $columns['id'][$params['cid']];
	} 
	else if (isset($params['cw']))
	{
		$word = $params['cw'];
		$percent = array();
		foreach ($columns['id'] as $val)
		{
			similar_text($word,$val['classname'],$per);
			$percent[$val['classid']] = $per;
		}
		natsort($percent);
		$c = array_keys($percent);
		$num = count($c);
		$cl = $column = $columns['id'][$c[($num-1)]];
	}
	
	$where[] = "my_article.classid={$column['classid']}";
	!isset($params['flag']) || $where[] = "flag like '%{$params['flag']}%'";
	$where = join(" and ",$where);
	!isset($params['order']) || $order = $params['order']." ".$params['sort'];

	$list = article::getArticleLimitPage($where,0,$params['row'],$order);
	$smarty->assign($params['var'],$list);
}

/* vim: set expandtab: */

?>
